import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

// import Home from '../views/Home.vue'
import index from "../views/Index"
import login from "../views/Login"
import register from "../views/Registe"
import forgetcode from "../views/ForgetCode"
import mine from "../views/Mine"
import happy from "../views/Happy"
import personalCenter from "../views/PersonalCenter"
import view from "../views/View"
import joke from "../views/Joke"
import constell from "../views/Constell"
import game from "../views/Game"
import guess from "../views/Guess"
import changeUser from "../views/ChangeUser"
import minePage from "../components/MinePage"


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/animation"
  },
  {
    path: '/about',
    name: 'About',
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: "/postList",
    component: () => import("../views/PostList.vue")
  },
  {
    path: "/postDetail",
    component: () => import("../views/PostDetail.vue")
  },
  {
    path: "/postPublish",
    component: () => import("../views/PostPublish.vue"),
    meta:{needLogin:true}
  },
  {
    path: "/index",
    component: index
  },
  {
    path: "/login",
    // component:()=>import("../views/Login")
    component: login
  },
  {
    path: "/register",
    // component:()=>import("../views/Login")
    component: register
  },
  {
    path: "/forgetcode",
    // component:()=>import("../views/Login")
    component: forgetcode
  },
  {
    path: "/mine",
    // component:()=>import("../views/Login")
    component: mine
  },
  {
    path: "/personalcenter",
    // component:()=>import("../views/Login")
    component: personalCenter
  },
  {
    path: "/happy",
    // component:()=>import("../views/Login")
    component: happy
  },
  {
    path: "/minePost",
    component: () => import("../views/MinePost"),
    meta:{needLoginminePost:true}
  },
  {
    path: "/mineComment",
    component: () => import("../views/MineComment"),
    meta:{needLoginmineComment:true}
  },
  {
    path: "/animation",
    component: () => import("../views/EnterAnimation")
  },
{
    path: "/view",
    // component:()=>import("../views/Login")
    component: view
  },
  {
    path: "/joke",
    // component:()=>import("../views/Login")
    component: joke
  },
  {
    path: "/constell",
    // component:()=>import("../views/Login")
    component: constell
  },
  {
    path: "/game",
    // component:()=>import("../views/Login")
    component: game
  },
  {
    path: "/guess",
    // component:()=>import("../views/Login")
    component: guess
  },
  {
    path: "/minePage",
    // component:()=>import("../views/Login")
    component: minePage
  },
  
  {
    path: "/change",
    // component:()=>import("../views/Login")
    component: changeUser
  },
  

]
import {userInfo} from "../api/api"
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  console.log(to)
  console.log(from)
  console.log(next)
  //哪些页面需要判断登录
  if(to.meta.needLogin){
  //  检测有没有登录
  userInfo().then(res=>{
      if(res.code == 0){
        next()
      }else {
        next("/index")
      }
    })

  } else { next() }
  // if(to.path == "/mine"){
  //   next("/course")
  // }else{
  //   next()
  // }

})



// const router = new VueRouter({
//   mode: 'history',
//   base: process.env.BASE_URL,
//   routes
// })

export default router
